package fr.afcepf.al22.qualite.dao.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;

import javax.sql.DataSource;

/**
 * @author Stagiaire
 *
 */
public class MyDatasource implements DataSource {
    /**
     * url.
     */
    private static String url;
    /**
     * driver.
     */
    private static String driver;
    /**
     * user.
     */
    private static String user;
    /**
     * pwd.
     */
    private static String pwd;
    static {
            Properties props = new Properties();
            try {
                props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("database.properties"));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            url = props.getProperty("url");
            driver = props.getProperty("driver");
            user = props.getProperty("user");
            pwd = props.getProperty("pwd");
            try {
                Class.forName(driver);
            } catch (ClassNotFoundException  e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

    @Override
    public PrintWriter getLogWriter() throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void setLogWriter(PrintWriter paramOut) throws SQLException {
        // TODO Auto-generated method stub
    }

    @Override
    public void setLoginTimeout(int paramSeconds) throws SQLException {
        // TODO Auto-generated method stub
    }

    @Override
    public int getLoginTimeout() throws SQLException {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T> T unwrap(Class<T> paramIface) throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> paramIface) throws SQLException {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Connection getConnection() throws SQLException {
        // TODO Auto-generated method stub
        return DriverManager.getConnection(url, user, pwd);
    }

    @Override
    public Connection getConnection(String paramUsername, String paramPassword)
            throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * @return the url
     */
    public static String getUrl() {
        return url;
    }

    /**
     * @param paramUrl the url to set
     */
    public static void setUrl(String paramUrl) {
        url = paramUrl;
    }

    /**
     * @return the driver
     */
    public static String getDriver() {
        return driver;
    }

    /**
     * @param paramDriver the driver to set
     */
    public static void setDriver(String paramDriver) {
        driver = paramDriver;
    }

    /**
     * @return the user
     */
    public static String getUser() {
        return user;
    }

    /**
     * @param paramUser the user to set
     */
    public static void setUser(String paramUser) {
        user = paramUser;
    }

    /**
     * @return the pwd
     */
    public static String getPwd() {
        return pwd;
    }

    /**
     * @param paramPwd the pwd to set
     */
    public static void setPwd(String paramPwd) {
        pwd = paramPwd;
    }

}
